package cm.java.jpa.inicial.test;

import cm.java.jpa.inicial.Endereco;
import cm.java.jpa.inicial.Noticia;
import cm.java.jpa.inicial.NoticiaId;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;


public class EnderecoTesteIntegrado {
    
    private static EntityManagerFactory emf = Persistence.createEntityManagerFactory("cmJavaJPATeste");
     
     private EntityManager em;
     private EntityTransaction tx;
     
    @Before
    public void iniciaGerenciadorEntidades() throws Exception {
        em = emf.createEntityManager();
        tx = em.getTransaction();
    }

    @After
    public void encerraGerenciadorEntidades() throws Exception {
        if (em != null) {
            em.close();
        }
    }
    @Test
    public void deveriaEncontrarEndereco() throws Exception{
        Endereco endereco = em.find(Endereco.class, 3000);
           assertEquals("Centro do Rio", endereco.getRua1());
    }
    
    @Test
    public void deveriaEncontrarNoticia() throws Exception{
        NoticiaId pk = new NoticiaId("Richard Wright has died on September 2008", "EN");
        Noticia noticia = em.find(Noticia.class, pk);
    }
}
